home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / inc / m68k.inc < prev    next >
Text File  |  1998-10-28  |  25KB  |  865 lines

  1. {
  2.     $Id: m68k.inc,v 1.10 1998/08/17 12:26:04 carl Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1993,97 by Carl-Eric Codere,
  5.     member of the Free Pascal development team.
  6.  
  7.     See the file COPYING.FPC, included in this distribution,
  8.     for details about the copyright.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  
  14.  **********************************************************************}
  15. {****************************************************************************
  16.  
  17.       m68k.inc : Processor dependent implementation of system unit
  18.                  For Motorola 680x0 Processor.
  19.  
  20. *****************************************************************************}
  21.  
  22. {****************************************************************************}
  23. {   Credit where credit is due:                                              }
  24. {   -Some of the copy routines taken from the Atari dlib source code:        }
  25. {     Dale Schumacher (alias: Dalnefre')  dal@syntel.uucp                    }
  26. {     399 Beacon Ave. St. Paul, MN 55104,USA                                 }
  27. {   -Some of the routines taken from the freeware ATARI Sozobon C compiler   }
  28. {      1988 by Sozobon, Limited.  Author: Johann Ruegg (freeware)            }
  29. {  Thanks to all these people wherever they maybe today!                     }
  30. {****************************************************************************}
  31.  
  32.  
  33.     { Don't call the following routines directly. }
  34.  Procedure Hlt;[public,alias: 'HALT_ERROR'];
  35.  { called by code generator on run-time errors. }
  36.  { on entry contains d0 = error code.           }
  37.  var
  38.   b:byte; { only byte is used... }
  39.  begin
  40.   asm
  41.      move.b d0,b
  42.   end;
  43.      HandleError(b);
  44.  end;
  45.  
  46.  
  47.  
  48.  
  49.    Procedure FillChar(var x; count: longint; value: byte);
  50.    begin
  51.      asm
  52.       move.l 8(a6), a0      { destination                   }
  53.       move.l 12(a6), d1     { number of bytes to fill       }
  54.       move.b 16(a6),d0      { fill data                     }
  55.       cmpi.l #65535, d1     { check, if this is a word move }
  56.       ble    @LMEMSET3      { use fast dbra mode            }
  57.       bra @LMEMSET2
  58.     @LMEMSET1:
  59.       move.b d0,(a0)+
  60.     @LMEMSET2:
  61.       subq.l #1,d1
  62.       cmp.b #-1,d1
  63.       bne  @LMEMSET1
  64.       bra @LMEMSET5        { finished slow mode , exit     }
  65.  
  66.     @LMEMSET4:             { fast loop mode section 68010+ }
  67.       move.b d0,(a0)+
  68.     @LMEMSET3:
  69.       dbra d1,@LMEMSET4
  70.  
  71.     @LMEMSET5:
  72.      end ['d0','d1','a0'];
  73.    end;
  74.  
  75.    Procedure FillObject(var x; count: longint; value: byte);
  76.    begin
  77.      asm
  78.       move.l 8(a6), a0      { destination                   }
  79.       move.l 12(a6), d1     { number of bytes to fill       }
  80.       move.w 16(a6),d0      { fill data                     }
  81.       cmp.l  #65535, d1     { check, if this is a word move }
  82.       ble    @LMEMSET3      { use fast dbra mode            }
  83.       bra @LMEMSET2
  84.     @LMEMSET1:
  85.       move.b d0,(a0)+
  86.     @LMEMSET2:
  87.       subq.l #1,d1
  88.       cmp.b #-1,d1
  89.       bne  @LMEMSET1
  90.       bra @LMEMSET5        { finished slow mode , exit     }
  91.  
  92.     @LMEMSET4:             { fast loop mode section 68010+ }
  93.       move.b d0,(a0)+
  94.     @LMEMSET3:
  95.       dbra d1,@LMEMSET4
  96.  
  97.     @LMEMSET5:
  98.      end ['d0','d1','a0'];
  99.    end;
  100.  
  101.     procedure int_help_constructor;
  102.  
  103.       begin
  104.          asm
  105.           XDEF HELP_CONSTRUCTOR
  106.             { Entry without preamble, since we need the ESP of the
  107.               constructor }
  108.             { Stack (relative to %ebp):
  109.                 12 Self
  110.                 8 VMT-Address
  111.                 4 main programm-Addr
  112.                 0 %ebp
  113.             }
  114.             { do we have to initialize self  }
  115.             { we just need to check for zero }
  116.             move.l    a5,d0
  117.             tst.l     d0      { set flags }
  118.             bne       @LHC_4
  119.  
  120.             { get memory, but save register first }
  121.             { temporary variable }
  122.             subq.l #4,sp
  123.             move.l sp,a5
  124.             { Save Registers }
  125.             movem.l d0-a7,-(sp)
  126.             { Memory size }
  127.             move.l 8(a6),a0
  128.             move.l (a0),-(sp)
  129.             { push method pointer }
  130.             move.l a5,-(sp)
  131.             jsr GETMEM
  132.             { Restore all registers in the correct order }
  133.             movem.l (sp)+,d0-a7
  134.             { Memory size to a5 }
  135.             move.l (a5),a5
  136.             add.l  #4,sp
  137.             { If no memory available : fail() }
  138.             move.l a5,d0
  139.             tst.l  d0         { set flags for a5 }
  140.             beq    @LHC_5
  141.             { init self for the constructor }
  142.             move.l a5,12(a6)
  143.          @LHC_4:
  144.             { is there a VMT address ? }
  145.             move.l 8(a6),d0
  146.             or.l   d0,d0
  147.             bne @LHC_7
  148.             { In case the constructor doesn't do anything, the Zero-Flag }
  149.             { can't be put, because this calls Fail() }
  150.             add.l  #1,d0
  151.             rts
  152.          @LHC_7:
  153.             { set zero inside the object }
  154.             { Save Registers }
  155.             movem.l d0-a7,-(sp)
  156.             move.w  #0,-(sp)
  157.  
  158.             move.l  8(a6),a0
  159.             move.l  (a0),-(sp)
  160.             move.l  a5,-(sp)
  161.             {                }
  162.             jsr  FILLOBJECT
  163.             { Restore all registers in the correct order }
  164.             movem.l (sp)+,d0-a7
  165.             { set the VMT address for the new created object }
  166.             move.l 8(a6),d0
  167.             move.l d0,(a5)
  168.             or.l d0,d0
  169.          @LHC_5:
  170.             rts
  171.          end;
  172.       end;
  173.  
  174.     procedure help_fail;
  175.  
  176.       begin
  177.          asm
  178.          end;
  179.       end;
  180.  
  181.     procedure int_help_destructor;
  182.  
  183.       begin
  184.          asm
  185.             { Stack (relative to %ebp):
  186.                 12 Self
  187.                 8 VMT-Address
  188.                 4 Main program-Addr
  189.                 0 %ebp
  190.             }
  191.             { temporary Variable }
  192.           XDEF HELP_DESTRUCTOR
  193.             subq.l #4,sp
  194.             move.l sp,d6
  195.             { Save Registers }
  196.             movem.l d0-a7,-(sp)
  197.  
  198.             move.l 8(a6),d0         { Get the address of the vmt }
  199.             or.l   d0,d0            { Check if there is a vmt    }
  200.             beq    @LHD_3
  201.             { Yes, get size from SELF! }
  202.             move.l 12(a6),a0
  203.             { get VMT-pointer (from Self) to %ebx }
  204.             move.l (a0),a1
  205.             { And put size on the Stack }
  206.             move.l (a1),-(sp)
  207.             { SELF }
  208.             { I think for precaution }
  209.             { that we should clear the VMT here }
  210.             clr.l (a0)
  211.             { get address of local variable into  }
  212.             { address register                    }
  213.             move.l d6,a1
  214.             move.l a0,(a1)
  215.             move.l a1,-(sp)
  216.             jsr    FREEMEM
  217.          @LHD_3:
  218.             { Restore all registers in the correct order }
  219.             movem.l (sp)+,d0-a7
  220.             add.l #4,sp
  221.             rts
  222.          end;
  223.       end;
  224.  
  225.   procedure new_class;assembler;
  226.  
  227.   asm
  228.      XDEF NEW_CLASS
  229.      { create class ? }
  230.      move.l 8(a6), d0
  231.      tst.l  d0
  232.      { check for nil... }
  233.      beq    @NEW_CLASS1
  234.  
  235.      { a5 contains vmt }
  236.      move.l a5,-(sp)
  237.      { call newinstance (class method!) }
  238.      jsr 16(a5)
  239.      { new instance returns a pointer to the new created }
  240.      { instance in d0                                    }
  241.      { load a5  and insert self                          }
  242.      move.l d0,8(a6)
  243.      move.l d0,a5
  244.      bra    @end
  245.   @NEW_CLASS1:
  246.      move.l a5,8(a6)
  247.   @end:
  248.   end;
  249.  
  250.  
  251.  
  252.   procedure dispose_class;assembler;
  253.  
  254.   asm
  255.     XDEF DISPOSE_CLASS
  256.      { destroy class ? }
  257.      move.l 8(a6),d0
  258.      { save self }
  259.      move.l a5,8(a6)
  260.      tst.l  d0
  261.      beq    @DISPOSE_CLASS
  262.      { no inherited call }
  263.      move.l (a5),d0
  264.      { push self }
  265.      move.l a5,-(sp)
  266.      { call freeinstance }
  267.      move.l d0,a0
  268.      jsr    20(a0)
  269.   @DISPOSE_CLASS:
  270.      { load self }
  271.      move.l 8(a6),a5
  272.   end;
  273.  
  274.   { checks for a correct vmt pointer }
  275.   procedure co;assembler;
  276.   { ON ENTRY: a0 -> Pointer to the VMT                  }
  277.   {   Nota: All registers must be preserved including   }
  278.   {   A0 itself!                                        }
  279.   asm
  280.    XDEF CHECK_OBJECT
  281.      move.l   d0,-(sp)
  282.      tst.l    a0
  283.      { z flag set if zero }
  284.      beq      @co_re
  285.  
  286.      move.l   (a0),d0
  287.      add.l    4(a0),d0
  288.      bne      @co_re
  289.      bra      @end
  290. @co_re:
  291.      move.l   (sp)+,d0
  292.      move.b   #210,d0
  293.      jsr      HALT_ERROR
  294. @end:
  295.      move.l   (sp)+,d0
  296.   end;
  297.  
  298.  
  299.  
  300.     function get_addr(BP : longint) : longint;
  301.       begin
  302.          asm
  303.             move.l BP,a0
  304.             cmp.l #0,a0
  305.             beq @Lnul_address
  306.             move.l 4(a0),a0
  307.          @Lnul_address:
  308.             move.l a0,@RESULT
  309.          end ['a0'];
  310.       end;
  311.  
  312.     function get_next_frame(bp : longint) : longint;
  313.  
  314.       begin
  315.          asm
  316.             move.l bp,a0
  317.             cmp.l  #0,a0
  318.             beq    @Lnul_frame
  319.             move.l (a0),a0
  320.          @Lnul_frame:
  321.             move.l a0,@RESULT
  322.          end ['a0'];
  323.       end;
  324.  
  325. Procedure HandleError (Errno : longint);[alias : 'handleerror'];
  326. {
  327.   Procedure to handle internal errors, i.e. not user-invoked errors
  328.   Internal function should ALWAYS call HandleError instead of RunError.
  329. }
  330.       function get_addr : pointer;
  331.  
  332.         begin
  333.            asm
  334.               move.l (a6),a0
  335.               move.l 4(a0),a0
  336.               move.l a0,@RESULT
  337.            end ['a0'];
  338.         end;
  339.       function get_error_bp : longint;
  340.  
  341.         begin
  342.            asm
  343.               { get base pointer of error }
  344.               move.l (a6),d0
  345.               move.l d0,@RESULT
  346.            end ['d0'];
  347.         end;
  348.  
  349. begin
  350.   If ErrorProc<>Nil then
  351.     TErrorProc (ErrorProc)(Errno,get_addr);
  352.   errorcode:=Errno;
  353.   exitcode:=Errno;
  354.   erroraddr:=Get_addr;
  355.   DoError := TRUE;
  356.   errorbase:=get_error_bp;
  357.   halt(errorcode);
  358. end;
  359.  
  360.  
  361.     procedure runerror(w : word);
  362.  
  363.       function get_addr : longint;
  364.  
  365.         begin
  366.            asm
  367.               move.l (a6),a0
  368.               move.l 4(a0),a0
  369.               move.l a0,@RESULT
  370.            end ['a0'];
  371.         end;
  372.  
  373.       function get_error_bp : longint;
  374.  
  375.         begin
  376.            asm
  377.               { get base pointer of error }
  378.               move.l (a6),d0
  379.               move.l d0,@RESULT
  380.            end ['d0'];
  381.         end;
  382.  
  383.       begin
  384.          errorcode:=w;
  385.          exitcode:=w;
  386.          erroraddr:=pointer(get_addr);
  387.          DoError:=True;
  388.          ErrorBase:=get_error_bp;
  389.          halt(byte(errorcode));
  390.       end;
  391.  
  392.     procedure io1(addr : longint);[public,alias: 'IOCHECK'];
  393.  
  394.       var
  395.          l : longint;
  396.  
  397.       begin
  398.          { Since IOCHECK is called directly and only later the optimiser }
  399.          { Maybe also save global registers  }
  400.          asm
  401.             movem.l d0-a7,-(sp)
  402.          end;
  403.          l:=ioresult;
  404.          if l<>0 then
  405.            begin
  406.               writeln('IO-Error ',l,' at 0x',HexStr(addr,8));
  407.               halt(byte(l));
  408.            end;
  409.          asm
  410.             { the register are put back in the correct order }
  411.             movem.l (sp)+,d0-a7
  412.          end;
  413.       end;
  414.  
  415.     procedure re_overflow;[public,alias: 'RE_OVERFLOW'];
  416.  
  417.       var
  418.          addr : longint;
  419.  
  420.       begin
  421.          { Overflow was shortly before the return address }
  422.          asm
  423.             move.l 4(a6),d0
  424.             move.l d0,addr
  425.          end;
  426.          writeln('Overflow at 0x',HexStr(addr,8));
  427.          HandleError(215);
  428.       end;
  429.  
  430. {    procedure strcopy(dstr,sstr : pointer;len : longint);[public,alias: 'STRCOPY'];}
  431.      procedure strcopy; assembler;
  432.     {---------------------------------------------------}
  433.     { Low-level routine to copy a string to another     }
  434.     { string with maximum length. Never call directly!  }
  435.     { On Entry:                                         }
  436.     {     a1.l = string to copy to                      }
  437.     {     a0.l = source string                          }
  438.     {     d0.l = maximum length of copy                 }
  439.     { registers destroyed: a0,a1,d0,d1                  }
  440.     {---------------------------------------------------}
  441.          asm
  442.            XDEF STRCOPY
  443. {            move.l 12(a6),a0
  444.             move.l 16(a6),a1
  445.             move.l 8(a6),d1 }
  446.             move.l d0,d1
  447.  
  448.             move.b (a0)+,d0     { Get source length }
  449.             and.w  #$ff,d0
  450.             cmp.w  d1,d0        { This is a signed comparison! }
  451.             ble    @LM4
  452.             move.b d1,d0        { If longer than maximum size of target, cut
  453.                                   source length }
  454.          @LM4:
  455.             andi.l #$ff,d0     { zero extend d0-byte }
  456.             move.l d0,d1       { save length to copy }
  457.             move.b d0,(a1)+    { save new length     }
  458.             { Check if copying length is zero - if so then }
  459.             { exit without copying anything.               }
  460.             tst.b  d1
  461.             beq    @Lend
  462.             bra    @LMSTRCOPY55
  463.          @LMSTRCOPY56:         { 68010 Fast loop mode }
  464.             move.b (a0)+,(a1)+
  465.          @LMSTRCOPY55:
  466.             dbra  d1,@LMSTRCOPY56
  467.          @Lend:
  468.       end;
  469.  
  470.     { Concatenate Strings }
  471.     { PARAMETERS ARE REVERSED COMPARED TO NORMAL! }
  472.     { therefore online assembler may not parse the params as normal }
  473.     procedure strconcat(s1,s2 : pointer);[public,alias: 'STRCONCAT'];
  474.  
  475.       begin
  476.          asm
  477.           move.b  #255,d0
  478.           move.l  s1,a0                { a0 = destination }
  479.           move.l  s2,a1                { a1 = source      }
  480.           sub.b   (a0),d0              {  copyl:= 255 -length(s1)    }
  481.           move.b  (a1),d6
  482.           and.w   #$ff,d0              { Sign flags are checked!     }
  483.           and.w   #$ff,d6
  484.           cmp.w   d6,d0                { if copyl > length(s2) then  }
  485.           ble     @Lcontinue
  486.           move.b  (a1),d0              {  copyl:=length(s2)          }
  487.     @Lcontinue:
  488.           move.b  (a0),d6
  489.           and.l   #$ff,d6
  490.           lea     1(a0,d6),a0          { s1[length(s1)+1]            }
  491.           add.l   #1,a1                { s2[1]                       }
  492.           move.b  d0,d6
  493.           { Check if copying length is zero - if so then }
  494.           { exit without copying anything.               }
  495.           tst.b  d6
  496.           beq    @Lend
  497.           bra    @ALoop
  498.     @Loop:
  499.           move.b  (a1)+,(a0)+          { s1[i] := s2[i];             }
  500.     @ALoop:
  501.           dbra    d6,@Loop
  502.           move.l  s1,a0
  503.           add.b   d0,(a0)              { change to new string length }
  504.     @Lend:
  505.          end ['d0','d1','a0','a1','d6'];
  506.       end;
  507.  
  508.     { Compares strings }
  509.     { DO NOT CALL directly.                                 }
  510.     {   a0 = pointer to first string to compare             }
  511.     {   a1 = pointer to second string to compare            }
  512.     {   ALL FLAGS are set appropriately.                    }
  513.     {    ZF = strings are equal                             }
  514.     { REGISTERS DESTROYED: a0, a1, d0, d1, d6               }
  515.     procedure strcmp; assembler;
  516.      asm
  517.      XDEF STRCMP
  518.  
  519.             move.b (a0)+,d0     { Get length of first string  }
  520.             move.b (a1)+,d6     { Get length of 2nd string    }
  521.  
  522.             move.b  d6,d1      { Save length of string for final compare   }
  523.  
  524.             cmp.b  d0,d6        { Get shortest string length   }
  525.             ble    @LSTRCONCAT1
  526.             move.b d0,d6       { Set length to shortest string }
  527.  
  528.          @LSTRCONCAT1:
  529.             tst.b  d6          { Both strings have a length of zero, exit }
  530.             beq    @LSTRCONCAT2
  531.  
  532.             andi.l  #$ff,d6
  533.  
  534.  
  535.             subq.l  #1,d6      { subtract first attempt                    }
  536.             { if value is -1 then don't loop and just compare lengths of   }
  537.             { both strings before exiting.                                 }
  538.             bmi     @LSTRCONCAT2
  539.             or.l    d0,d0      { Make sure to set Zerfo flag to 0          }
  540.          @LSTRCONCAT5:
  541.             { Workaroung for GAS v.134 bug }
  542.             {  old: cmp.b (a1)+,(a0)+      }
  543.             cmpm.b  (a1)+,(a0)+
  544.          @LSTRCONCAT4:
  545.             dbne    d6,@LSTRCONCAT5   { Repeat until not equal }
  546.             bne     @LSTRCONCAT3
  547.           @LSTRCONCAT2:
  548.             { If length of both string are equal }
  549.             { Then set zero flag                 }
  550.             cmp.b   d1,d0   { Compare length - set flag if equal length strings }
  551.          @LSTRCONCAT3:
  552.      end;
  553.  
  554.  
  555.   Function strpas(p: pchar): string;
  556.   { only 255 first characters are actually copied. }
  557.    var
  558.     counter : byte;
  559.     str: string;
  560.   Begin
  561.      counter := 0;
  562.      str := '';
  563.      while (ord(p[counter]) <> 0) and (counter < 255) do
  564.      begin
  565.         counter:=counter+1;
  566.         str[counter] := char(p[counter-1]);
  567.      end;
  568.      str[0] := char(counter);
  569.      strpas := str;
  570.   end;
  571.  
  572.   function strlen(p : pchar) : longint;
  573.   var
  574.      counter : longint;
  575.   Begin
  576.        counter := 0;
  577.        repeat
  578.           counter:=counter+1;
  579.        until ord(p[counter]) = 0;
  580.        strlen := counter;
  581.   end;
  582.  
  583.  
  584.    procedure move(var source;var dest;count : longint);
  585.    { base pointer+8 = source                  }
  586.    { base pointer+12 = destination            }
  587.    { base pointer+16 = number of bytes to move}
  588.    begin
  589.      asm
  590.       clr.l      d0
  591.       move.l   16(a6),d0   {  number of bytes }
  592.     @LMOVE0:
  593.       move.l   12(a6),a1   {  destination          }
  594.       move.l   8(a6),a0      {  source               }
  595.  
  596.       cmpi.l #65535, d0     { check, if this is a word move }
  597.       ble    @LMEMSET00     { use fast dbra mode 68010+     }
  598.  
  599.       cmp.l      a0,a1         {  check copy direction }
  600.       bls      @LMOVE4
  601.       add.l      d0,a0         { move pointers to end  }
  602.       add.l      d0,a1
  603.       bra     @LMOVE2
  604.     @LMOVE1:
  605.       move.b   -(a0),-(a1)   {  (s < d) copy loop }
  606.     @LMOVE2:
  607.       subq.l    #1,d0
  608.       cmpi.l    #-1,d0
  609.       bne       @LMOVE1
  610.       bra       @LMOVE5
  611.     @LMOVE3:
  612.       move.b  (a0)+,(a1)+  { (s >= d) copy loop }
  613.     @LMOVE4:
  614.       subq.l    #1,d0
  615.       cmpi.l    #-1,d0
  616.       bne       @LMOVE3
  617.       bra       @LMOVE5
  618.  
  619.     @LMEMSET00:            { use fast loop mode 68010+ }
  620.       cmp.l      a0,a1         {  check copy direction }
  621.       bls      @LMOVE04
  622.       add.l      d0,a0         { move pointers to end  }
  623.       add.l      d0,a1
  624.       bra     @LMOVE02
  625.     @LMOVE01:
  626.       move.b   -(a0),-(a1)   {  (s < d) copy loop }
  627.     @LMOVE02:
  628.       dbra      d0,@LMOVE01
  629.       bra       @LMOVE5
  630.     @LMOVE03:
  631.       move.b  (a0)+,(a1)+  { (s >= d) copy loop }
  632.     @LMOVE04:
  633.       dbra      d0,@LMOVE03
  634.     { end fast loop mode }
  635.     @LMOVE5:
  636.     end ['d0','a0','a1'];
  637.    end;
  638.  
  639.  
  640.     procedure fillword(var x;count : longint;value : word);
  641.  
  642.       begin
  643.      asm
  644.       move.l 8(a6), a0      { destination             }
  645.       move.l 12(a6), d1     { number of bytes to fill }
  646.       move.w 16(a6),d0      { fill data               }
  647.       bra @LMEMSET21
  648.     @LMEMSET11:
  649.       move.w d0,(a0)+
  650.     @LMEMSET21:
  651.       subq.l #1,d1
  652.       cmp.b #-1,d1
  653.       bne  @LMEMSET11
  654.      end ['d0','d1','a0'];
  655.    end;
  656.  
  657.  
  658.     function abs(l : longint) : longint;
  659.  
  660.       begin
  661.          asm
  662.             move.l 8(a6),d0
  663.             tst.l  d0
  664.             bpl @LMABS1
  665.             neg.l d0
  666.          @LMABS1:
  667.             move.l d0,@RESULT
  668.          end ['d0'];
  669.       end;
  670.  
  671.     function odd(l : longint) : boolean;
  672.  
  673.       begin
  674.         if (l and $01) = $01 then
  675.           odd := TRUE
  676.         else
  677.           odd := FALSE;
  678.       end;
  679.  
  680.     function sqr(l : longint) : longint;
  681.  
  682.       begin
  683.          sqr := l*l;
  684.       end;
  685.  
  686.     procedure int_str(l : longint;var s : string);
  687.  
  688.       var
  689.         value: longint;
  690.         negative: boolean;
  691.  
  692.       begin
  693.          negative := false;
  694.          s:='';
  695.          { Workaround: }
  696.          if l=$80000000 then
  697.            begin
  698.               s:='-2147483648';
  699.               exit;
  700.            end;
  701.         { handle case where l = 0 }
  702.          if l = 0 then
  703.          begin
  704.            s:='0';
  705.            exit;
  706.          end;
  707.          If l < 0 then
  708.          begin
  709.              negative := true;
  710.              value:=abs(l);
  711.          end
  712.          else
  713.              value:=l;
  714.        { handle non-zero case }
  715.        while value>0 do
  716.          begin
  717.             s:=char((value mod 10)+ord('0'))+s;
  718.             value := value div 10;
  719.          end;
  720.          if negative then
  721.            s := '-' + s;
  722.       end;
  723.  
  724.  
  725. {$IFNDEF NEW_READWRITE}
  726.     procedure f1;[public,alias: 'FLUSH_STDOUT'];
  727.  
  728.       begin
  729.          asm
  730.             { Save Registers }
  731.             movem.l d0-a7,-(sp)
  732.          end;
  733.          FileFunc(textrec(output).flushfunc)(textrec(output));
  734.          asm
  735.             { Restore all registers in the correct order }
  736.             movem.l (sp)+,d0-a7
  737.          end;
  738.       end;
  739. {$ENDIF NEW_READWRITE}
  740.  
  741. Function Sptr : Longint;
  742. begin
  743.   asm
  744.     move.l sp,d0
  745.     add.l  #8,d0
  746.     move.l d0,@RESULT
  747.   end ['d0'];
  748. end;
  749.  
  750.  
  751.  
  752.  
  753.  Procedure BoundsCheck;assembler;
  754.  { called by code generator with R+ state to    }
  755.  { determine if a range check occured.          }
  756.  { Only in 68000 mode, in 68020 mode this is    }
  757.  { inline.                                      }
  758.  { On Entry:                                    }
  759.  {   A1 = address contaning min and max indexes }
  760.  {   D0 = value of current index to check.      }
  761.  asm
  762. XDEF RE_BOUNDS_CHECK
  763.   cmp.l   (A1),D0        { lower bound ...    }
  764.   bmi     @rebounderr    { is index lower ... }
  765.   add.l   #4,A1
  766.   cmp.l   (A1),D0
  767.   bmi     @reboundend
  768.   beq     @reboundend
  769. @rebounderr:
  770.   move.l  #201,d0
  771.   jsr     HALT_ERROR
  772. @reboundend:
  773.  end;
  774.  
  775. {
  776.   $Log: m68k.inc,v $
  777.   Revision 1.10  1998/08/17 12:26:04  carl
  778.     + simple cleanup of comments
  779.  
  780.   Revision 1.9  1998/07/30 13:26:14  michael
  781.   + Added support for ErrorProc variable. All internal functions are required
  782.     to call HandleError instead of runerror from now on.
  783.     This is necessary for exception support.
  784.  
  785.   Revision 1.8  1998/07/10 11:02:41  peter
  786.     * support_fixed, becuase fixed is not 100% yet for the m68k
  787.  
  788.   Revision 1.7  1998/07/02 12:20:58  carl
  789.     + Io-Error and overflow print erroraddr in hex now
  790.  
  791.   Revision 1.6  1998/07/01 14:25:57  carl
  792.     * strconcat was copying one byte too much
  793.     * strcopy bugfix was using signed comparison
  794.     + STRCOPY uses register calling conventions
  795.     * FillChar bugfix was loading a word instead of a byte
  796.  
  797.   Revision 1.2  1998/03/27 23:48:06  carl
  798.     * bugfix of STRCONCAT alignment problem
  799.  
  800.   Revision 1.18  1998/03/02 04:17:24  carl
  801.     * problem with CHECK_OBJECT fixed, will probably only work with
  802.       GNU tools, as the VMT pointer is an .lcomm and might not be
  803.       zeroed automatically by other loaders.
  804.     * CHECK_OBJECT was not jumping on right condition
  805.  
  806.   Revision 1.17  1998/02/23 02:26:06  carl
  807.     * bugfix to make it link without problems
  808.  
  809.   Revision 1.13  1998/02/06 16:35:35  carl
  810.     * oops commited wrong file
  811.  
  812.   Revision 1.11  1998/01/26 12:01:32  michael
  813.   + Added log at the end
  814.  
  815.  
  816.   
  817.   Working file: rtl/m68k/m68k.inc
  818.   description:
  819.   ----------------------------
  820.   revision 1.10
  821.   date: 1998/01/19 10:21:36;  author: michael;  state: Exp;  lines: +1 -12
  822.   * moved Fillchar t(..,char) to system.inc
  823.   ----------------------------
  824.   revision 1.9
  825.   date: 1998/01/13 03:47:39;  author: carl;  state: Exp;  lines: +3 -3
  826.     * bugfix of BoundsCheck invalid opcodes
  827.   ----------------------------
  828.   revision 1.8
  829.   date: 1998/01/13 03:24:58;  author: carl;  state: Exp;  lines: +2 -2
  830.     * moveq.l #201 bugfix (This is of course an impossible opcode)
  831.   ----------------------------
  832.   revision 1.7
  833.   date: 1998/01/12 15:24:47;  author: carl;  state: Exp;  lines: +1 -20
  834.     * bugfix, a function was being duplicated.
  835.   ----------------------------
  836.   revision 1.6
  837.   date: 1998/01/12 03:40:11;  author: carl;  state: Exp;  lines: +2 -2
  838.     * bugfix of RE_OVERFLOW, now gives out a runerror(215)
  839.   ----------------------------
  840.   revision 1.5
  841.   date: 1998/01/05 00:31:43;  author: carl;  state: Exp;  lines: +206 -119
  842.   * Bugfix of syntax errors
  843.   ----------------------------
  844.   revision 1.4
  845.   date: 1998/01/01 16:50:16;  author: michael;  state: Exp;  lines: +1 -21
  846.   - Moved Do_exit to system.inc. Now processor independent.
  847.   ----------------------------
  848.   revision 1.3
  849.   date: 1997/12/10 12:15:05;  author: michael;  state: Exp;  lines: +2 -2
  850.   * changed dateifunc to FileFunc.
  851.   ----------------------------
  852.   revision 1.2
  853.   date: 1997/12/01 12:37:21;  author: michael;  state: Exp;  lines: +14 -0
  854.   + added copyright reference in header.
  855.   ----------------------------
  856.   revision 1.1
  857.   date: 1997/11/27 08:33:48;  author: michael;  state: Exp;
  858.   Initial revision
  859.   ----------------------------
  860.   revision 1.1.1.1
  861.   date: 1997/11/27 08:33:48;  author: michael;  state: Exp;  lines: +0 -0
  862.   FPC RTL CVS start
  863.   =============================================================================
  864. }
  865.